package com.ipt.frm.pw;

import java.io.IOException;
import java.util.ArrayList;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.ipartek.fila2.bean.Alumno;
import com.ipartek.fila2.factoria.DAOFactory;
import com.ipartek.fila2.interfaces.InterfaceAlumnoDAO;
import com.ipartek.fila2.interfaces.InterfaceTiradaDAO;


/**
 * Servlet implementation class ServletRanking
 */
public class ServletRanking extends HttpServlet {
	private static final long serialVersionUID = 1L;
	private static DAOFactory fMySQL;
	private static InterfaceAlumnoDAO aDao;
	private static InterfaceTiradaDAO tDao;
	private static final String TABLE_ALUMNO = "alumno";
	private static final String TABLE_TIRADA = "tirada";   
    /**
     * @see HttpServlet#HttpServlet()
     */
    public ServletRanking() {
        super();
        // TODO Auto-generated constructor stub
    }
    
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException{
    	/*int listaUser[] = new int[10];
    	for(int i = 0;i<10;i++){
    		listaUser[i] = i;
    	}*/
    	
		fMySQL = DAOFactory.getDAOFactory(DAOFactory.MYSQL);

		aDao = fMySQL.getInterfaceAlumnoDAO();
		tDao = fMySQL.getInterfaceTiradaDAO();
		
    	ArrayList<Alumno> ListaUser = null;
		try {
			ListaUser = aDao.getAlumnosActivos(TABLE_ALUMNO);
			request.setAttribute("lista", ListaUser);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

    	RequestDispatcher dispacher = this.getServletContext().getRequestDispatcher("/ranking.jsp");
    	dispacher.forward(request, response);
    }
    

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	@Override
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		 processRequest(request,response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	@Override
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		 processRequest(request,response);
	}

}
